package com.ruoyi.costumeShop.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.costumeShop.domain.SaleOrderCostume;
import com.ruoyi.costumeShop.mapper.CostumeMapper;
import com.ruoyi.costumeShop.service.ISaleOrderCostumeService;
import com.ruoyi.costumeShop.vo.DashBoardVO;
import com.ruoyi.costumeShop.vo.InputVO;
import com.ruoyi.costumeShop.vo.OrderVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;
@RestController
@RequestMapping("saleOrderCostume")
public class SaleOrderCostumeController extends BaseController {
    @Autowired
    private ISaleOrderCostumeService saleOrderCostumeService;

    @Autowired
    private RedisTemplate redisTemplate;

    @Autowired
    private CostumeMapper itemMapper;

    @GetMapping("/createOrder")
    public ResponseEntity<InputVO> createOrder() {
        InputVO inputVO = this.saleOrderCostumeService.createOrder();
        System.out.println(inputVO.getCostumeNo());
        return ResponseEntity.ok(this.saleOrderCostumeService.createOrder());
    }

    @GetMapping("/commitOrder")
    public Boolean commitOrder(OrderVO orderVO) {
        return this.saleOrderCostumeService.commitOrder(orderVO);
    }

    @GetMapping("/pie")
    public ResponseEntity<List<DashBoardVO>> pie() {
        return ResponseEntity.ok(this.saleOrderCostumeService.countByCategoryId());
    }

    @GetMapping("/identifyCostume")
    public ResponseEntity<Map<String, Object>> identifyItem(InputVO inputVO) {
        System.out.println("订单号：" + inputVO.getOrderNo());
        System.out.println("服装编号：" + inputVO.getCostumeNo());
        System.out.println("尺码：" + inputVO.getSize());
        return ResponseEntity.ok(this.saleOrderCostumeService.enterLineOrderItemVO(inputVO));
    }


    /**
     * 分页查询
     *
     * @param orderItem 筛选条件
     * @return 查询结果
     */
    @GetMapping("/list")
    public ResponseEntity<List<SaleOrderCostume>> queryAll(SaleOrderCostume orderItem) {
        return ResponseEntity.ok(this.saleOrderCostumeService.queryAll(orderItem));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<SaleOrderCostume> queryById(@PathVariable("id") Long id) {
        return ResponseEntity.ok(this.saleOrderCostumeService.queryById(id));
    }


    /**
     * 编辑数据
     * @param orderItem 实体
     * @return 编辑结果
     */
     @PutMapping
     public ResponseEntity<SaleOrderCostume> edit(@RequestBody SaleOrderCostume orderItem) {
        return ResponseEntity.ok(this.saleOrderCostumeService.update(orderItem));
     }

     /**
      * 删除数据
      *
      * @param id 主键
      * @return 删除是否成功
      */
     @DeleteMapping("/delete/{id}")
     public ResponseEntity<Boolean> deleteById(@PathVariable Long id) {
         return ResponseEntity.ok(this.saleOrderCostumeService.deleteById(id));
     }

     @GetMapping("/page")
     public PageInfo page(@RequestParam("pageNum") Integer pageNum, @RequestParam("pageSize") Integer pageSize, SaleOrderCostume orderItem) {
         PageHelper.startPage(pageNum, pageSize);
         List<SaleOrderCostume> list = this.saleOrderCostumeService.queryAll(orderItem);
         PageInfo<List> pageInfo = new PageInfo(list);
         return pageInfo;
     }
}
